import Vue from 'vue'
import Router from 'vue-router'
/* Layout */
import Layout from '@/layout'
import ParentView from '@/layout/components/ParentView'

Vue.use(Router)

/**
 * 注意：子菜单仅在 route children.length >= 1 时出现
 * 详细信息： https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   如果设置为 true，则 item 将不会显示在侧边栏中（默认为 false）
 * alwaysShow: true               如果设置为 true，将始终显示根菜单
 *                                如果未设置 alwaysShow，则当 item 有多个 children 路由时，
 *                                它将变为嵌套模式，否则不显示根菜单
 * redirect: noRedirect          如果设置，noRedirect 将不会在面包屑中重定向
 * name:'router-name'             名称由 <keep-alive> （Must Set!!） 使用
 * meta : {
    roles: ['admin','editor']    控制页面角色（您可以设置多个角色）
    title: 'title'               名称 Show in Sidebar 和 Breadcrumb （Recommend Set）
    icon: 'svg-name'/'el-icon-x' 侧边栏中的图标显示
    breadcrumb: false            如果设置为 false，则项目将隐藏在面包屑中（默认为 true）
    activeMenu: '/example/list'  如果 Set path （设置路径），侧边栏将高亮显示您设置的路径
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'fa-solid fa-home' }
    }]
  },

  {
    path: '/client',
    name: 'Client',
    component: Layout,
    meta: { title: '应用管理', icon: 'fa-solid fa-bars-progress' },
    children: [
      {
        path: 'list',
        component: () => import('@/views/client/list/index'),
        name: 'ClientIndex',
        meta: { title: '应用列表', icon: 'fa-solid fa-list' }
      },
      {
        path: 'category',
        component: () => import('@/views/client/category/index'),
        name: 'ClientCategory',
        meta: { title: '应用分类', icon: 'fa-solid fa-table-cells-large' }
      }
    ]
  },
  {
    path: '/dept',
    redirect: '/dept/index',
    component: Layout,
    children: [{
      path: 'index',
      component: () => import('@/views/dept/index'),
      name: 'Dept',
      meta: { title: '部门管理', icon: 'fa-solid fa-sitemap' }
    }]
  },
  {
    path: '/role',
    redirect: '/role/index',
    component: Layout,
    children: [{
      path: 'index',
      component: () => import('@/views/role/index'),
      name: 'Role',
      meta: { title: '角色管理', icon: 'fa-solid fa-user-tag' }
    }]
  },
  {
    path: '/user',
    redirect: '/user/index',
    component: Layout,
    children: [
      {
        path: 'profile',
        component: () => import('@/views/user/profile/index'),
        hidden: true
      },
      {
        path: 'index',
        component: () => import('@/views/user/index'),
        name: 'User',
        meta: { title: '用户管理', icon: 'fa-solid fa-user' }
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    meta: { title: '系统管理', icon: 'fa-solid fa-bars-progress' },
    children: [
      {
        path: '/system/monitor',
        name: 'Monitor',
        component: ParentView,
        meta: { title: '系统监控', icon: 'fa-solid fa-display' },
        children: [{
          path: 'online-user',
          component: () => import('@/views/system/monitor/online-user/index'),
          name: 'OnlineUserMonitor',
          meta: { title: '在线用户', icon: 'fa-solid fa-network-wired' }
        },
        {
          path: 'druid',
          name: 'DruidMonitor',
          meta: { title: '数据监控', icon: 'fa-solid fa-database', link: `${window.ssoConfig.serverUrl}/druid/login.html` }
        },
        {
          path: 'server',
          component: () => import('@/views/system/monitor/server/index'),
          name: 'ServerMonitor',
          meta: { title: '服务监控', icon: 'fa-solid fa-server' }
        }
        ]
      },
      {
        path: '/logs',
        name: 'Logs',
        component: ParentView,
        meta: { title: '日志管理', icon: 'fa-solid fa-clipboard' },
        children: [{
          path: 'login',
          component: () => import('@/views/system/logs/login/index'),
          name: 'LoginLog',
          meta: { title: '登录日志', icon: 'fa-solid fa-address-card' }
        },
        {
          path: 'operate',
          component: () => import('@/views/system/logs/operate/index'),
          name: 'OperateLog',
          meta: { title: '操作日志', icon: 'fa-solid fa-user-pen' }
        }
        ]
      }
    ]
  },

  // 404 页面必须放在末尾!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode： 'history'， // 需要服务支持
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// 详情请参阅： https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
